package com.ds.msg.mqtt.command.filter.command;

import com.ds.cluster.ServerNode;
import com.ds.common.JDSException;
import com.ds.engine.JDSSessionHandle;
import com.ds.msg.Msg;
import com.ds.msg.filter.MsgFilter;
import com.ds.msg.filter.MsgFilterChain;
import com.ds.msg.mqtt.command.filter.appmsg.LogDataFilterImpl;
import com.ds.msg.mqtt.command.filter.appmsg.SMSDataFilterImpl;
import com.ds.msg.mqtt.command.filter.appmsg.SystemMsgFilterImpl;
import com.ds.server.JDSServer;

/**
 * @author wenzhang
 */
public class LocalMsgFilterImpl implements MsgFilter {


    public LocalMsgFilterImpl() {

    }

    /**
     * 应用应该实现的过滤方法。
     *
     * @param msg 需要过滤的对象
     * @return
     */
    public boolean filterObject(Msg msg, JDSSessionHandle handle) {

        ServerNode currServerBean = null;
        try {
            currServerBean = JDSServer.getInstance().getCurrServerBean();

            this.process(msg, handle);
            return true;


        } catch (JDSException e) {
            e.printStackTrace();
        }
        return false;

    }


    private boolean process(Msg msg, JDSSessionHandle handle) throws JDSException {
        MsgFilterChain chain = new MsgFilterChain();
        chain.addFilter(new LogDataFilterImpl());
        chain.addFilter(new SMSDataFilterImpl());
        chain.addFilter(new SystemMsgFilterImpl());

        return chain.filterObject(msg, handle);
    }


}
